
********************************************************************************
$ontext
This is the numerical bottom-up optimization model used in
St�ckl, F. and A. Zerrahn (2020): Substituting Clean for Dirty Energy: A Bottom-Up Analysis

This model is derived from
The Dispatch and Investment Evaluation Tool with Endogenous Renewables (DIETER).
Version 1.3.0, November 2018.
Written by Alexander Zerrahn and Wolf-Peter Schill.

This work is licensed under the MIT License (MIT).
For more information on this license, visit http://opensource.org/licenses/mit-license.php.
Whenever you use this code, please refer to http://www.diw.de/dieter.
We are happy to receive feedback under azerrahn@diw.de and wschill@diw.de.
$offtext
********************************************************************************




*****************************************
**** Reporting to Excel              ****
*****************************************


Parameter
excel_capacities
excel_capacities_storage_power_in
excel_capacities_storage_power_out
excel_capacities_storage_energy
excel_cost_dispatch
excel_cost_investment
excel_cost_fix
excel_flh_generation
excel_flh_storage
excel_cost_total
excel_energy_demand
excel_cost_lcoe
excel_model_status

report_tech
;

excel_capacities('Capacities',loop_res_share,tech) = sum( n , sum( scen$(map(scen,loop_res_share)) , lev_N_TECH(scen,n,tech))) ;
excel_capacities_storage_power_in('Capacities',loop_res_share,sto) = sum( n , sum( scen$(map(scen,loop_res_share)) , lev_N_STO_P_IN(scen,n,sto))) ;
excel_capacities_storage_power_out('Capacities',loop_res_share,sto) = sum( n , sum( scen$(map(scen,loop_res_share)) , lev_N_STO_P_OUT(scen,n,sto))) ;
excel_capacities_storage_energy('Capacities',loop_res_share,sto) = sum( n , sum( scen$(map(scen,loop_res_share)) , lev_N_STO_E(scen,n,sto))) ;

excel_cost_investment('Nodal cost: investment',loop_res_share,tech) = sum(scen$(map(scen,loop_res_share)) , sum( n , kappa_i(n,tech)*lev_N_TECH(scen,n,tech))) ;
excel_cost_investment('Nodal cost: investment',loop_res_share,sto) = sum(scen$(map(scen,loop_res_share)) ,  sum( n , kappa_i_sto_e(n,sto)*lev_N_STO_E(scen,n,sto) + kappa_i_sto_p_in(n,sto)*lev_N_STO_P_IN(scen,n,sto) + kappa_i_sto_p_out(n,sto)*lev_N_STO_P_OUT(scen,n,sto) )) ;
excel_cost_fix('Nodal cost: fix',loop_res_share,tech) = sum(scen$(map(scen,loop_res_share)) , sum( n , kappa_fix(n,tech)*lev_N_TECH(scen,n,tech))) ;
excel_cost_fix('Nodal cost: fix',loop_res_share,sto) = sum(scen$(map(scen,loop_res_share)) ,  sum( n , kappa_fix_sto_e(n,sto)*lev_N_STO_E(scen,n,sto) + kappa_fix_sto_p_out(n,sto)*lev_N_STO_P_OUT(scen,n,sto) + kappa_fix_sto_p_in(n,sto)*lev_N_STO_P_IN(scen,n,sto) )) ;

excel_cost_dispatch('Nodal cost: dispatch',loop_res_share,dis) = sum( h , sum(scen$(map(scen,loop_res_share)) , sum( n , kappa_v(n,dis)*lev_G(scen,n,dis,h) ))) ;
excel_cost_dispatch('Nodal cost: dispatch',loop_res_share,sto) = sum( h , sum(scen$(map(scen,loop_res_share)) , sum( n , kappa_v_sto_in(n,sto) * lev_STO_IN(scen,n,sto,h) + kappa_v_sto_out(n,sto) * lev_STO_OUT(scen,n,sto,h) ) )) ;

report_tech('FLH',loop_res_share,con,n)$(sum(scen$(map(scen,loop_res_share)) , lev_N_TECH(scen,n,con)) > 1) = sum( h , sum(scen$(map(scen,loop_res_share)) , lev_G(scen,n,con,h)) ) / sum(scen$(map(scen,loop_res_share)) , lev_N_TECH(scen,n,con)) ;
report_tech('FLH',loop_res_share,res,n)$(sum(scen$(map(scen,loop_res_share)) , lev_N_TECH(scen,n,res)) > 1) = sum( h , sum(scen$(map(scen,loop_res_share)) , lev_G(scen,n,res,h) + lev_G_RES(scen,n,res,h) )) / sum(scen$(map(scen,loop_res_share)) , lev_N_TECH(scen,n,res)) ;

report_tech('FLH',loop_res_share,sto,n)$(sum(scen$(map(scen,loop_res_share)) , lev_N_STO_P_OUT(scen,n,sto)) > 1) = sum(h, sum(scen$(map(scen,loop_res_share)) , lev_STO_OUT(scen,n,sto,h) ) ) / sum(scen$(map(scen,loop_res_share)) , lev_N_STO_P_OUT(scen,n,sto)) ;
excel_flh_generation('FLH',loop_res_share,tech) = sum( n , report_tech('FLH',loop_res_share,tech,n) ) ;
excel_flh_storage('FLH',loop_res_share,sto) = sum( n , report_tech('FLH',loop_res_share,sto,n) ) ;

excel_cost_total('Nodal cost: total',loop_res_share,'') = sum(scen$(map(scen,loop_res_share)) , lev_Z(scen) ) ;
excel_energy_demand('Consumer energy demand',loop_res_share,'') = sum(scen$(map(scen,loop_res_share)) , sum( (h,n) , delta(n,h) )) ;
excel_model_status('Model status',loop_res_share,'') = sum(scen$(map(scen,loop_res_share)) , modstats(scen,'modelstat')) ;
excel_cost_lcoe('Nodal cost: lcoe',loop_res_share,'') = excel_cost_total('Nodal cost: total',loop_res_share,'') /  excel_energy_demand('Consumer energy demand',loop_res_share,'');



execute_unload "results_to_excel",
excel_capacities
excel_capacities_storage_power_in
excel_capacities_storage_power_out
excel_capacities_storage_energy
excel_cost_dispatch
excel_cost_investment
excel_cost_fix
excel_flh_generation
excel_flh_storage
excel_cost_total
excel_energy_demand
excel_cost_lcoe
excel_model_status
;

execute 'gdxxrw.exe results_to_excel.gdx par=excel_capacities rng=capacities!a2' ;
execute 'gdxxrw.exe results_to_excel.gdx par=excel_capacities_storage_power_in rng=capacities!o2' ;
execute 'gdxxrw.exe results_to_excel.gdx par=excel_capacities_storage_power_out rng=capacities!u2' ;
execute 'gdxxrw.exe results_to_excel.gdx par=excel_capacities_storage_energy  rng=capacities!ab2' ;

execute 'gdxxrw.exe results_to_excel.gdx par=excel_cost_dispatch rng=cost_dispatch!a2' ;
execute 'gdxxrw.exe results_to_excel.gdx par=excel_cost_investment rng=cost_investment!a2' ;
execute 'gdxxrw.exe results_to_excel.gdx par=excel_cost_fix rng=cost_fix!a2' ;

execute 'gdxxrw.exe results_to_excel.gdx par=excel_flh_generation rng=flh!a2' ;
execute 'gdxxrw.exe results_to_excel.gdx par=excel_flh_storage rng=flh!o2' ;

execute 'gdxxrw.exe results_to_excel.gdx par=excel_cost_total  rng=indicators!a2' ;
execute 'gdxxrw.exe results_to_excel.gdx par=excel_energy_demand  rng=indicators!f2' ;
execute 'gdxxrw.exe results_to_excel.gdx par=excel_cost_lcoe rng=indicators!l2' ;
execute 'gdxxrw.exe results_to_excel.gdx par=excel_model_status rng=indicators!q2' ;
